<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\UserApplyRiskLog
 *
 * @property int $id
 * @property int $loan_request_id 授信申请表ID
 * @property string $risk_id 风控查询ID
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserApplyRiskLog byRiskId($riskId)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserApplyRiskLog newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserApplyRiskLog newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserApplyRiskLog query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserApplyRiskLog whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserApplyRiskLog whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserApplyRiskLog whereLoanRequestId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserApplyRiskLog whereRiskId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserApplyRiskLog whereUpdatedAt($value)
 * @mixin \Eloquent
 * @property string $reason 风控审批结果
 * @property int $limit 授信额度
 * @property int $status 风控提交状态 0=初始状态 1=通过 2=拒绝 3=继续 4=处理中 5=数据不全 6=风控错误
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserApplyRiskLog whereLimit($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserApplyRiskLog whereReason($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserApplyRiskLog whereStatus($value)
 */
class UserApplyRiskLog extends Model
{
    /**
     * 初始
     */
    const STATUS_DEFAULT = 0;
    /**
     * 通过
     */
    const STATUS_SUCCESS = 1;
    /**
     * 拒绝
     */
    const STATUS_FAILED = 2;
    /**
     * 继续
     */
    const STATUS_CONTINUE = 3;
    /**
     * 处理中
     */
    const STATUS_PROCESSING = 4;
    /**
     * 数据不全
     */
    const STATUS_DATA_MISS = 5;
    /**
     * 错误
     */
    const STATUS_ERROR = 6;

    //状态映射
    static $STATUS = [
        'AA'    => self::STATUS_SUCCESS,
        'AD'    => self::STATUS_FAILED,
        'CT'    => self::STATUS_CONTINUE,
        'ERROR' => self::STATUS_ERROR,
        'RETRY' => self::STATUS_DATA_MISS,
        'P'     => self::STATUS_PROCESSING,
    ];
    //
    protected $fillable = ['loan_request_id','risk_id','reason','limit','status'];


    public function scopeByRiskId($query,$riskId){
        return $query->where('risk_id', $riskId);
    }

    public function getLimitAttribute(){
        return $this->attributes['limit'] / 100;
    }

    public function setLimitAttribute($value){
        $this->attributes['limit'] = $value * 100;
    }

}
